
/**
 * _tpl(tplStr,data) 取自underscore
 */
(function () {
    var _isObject = function (obj) {
        var type = typeof obj;
        return type === 'function' || type === 'object' && !!obj;
    };
    var hasOwnProperty = Object.prototype.hasOwnProperty;
    var _has = function (obj, key) {
        return obj != null && hasOwnProperty.call(obj, key);
    };
    var nativeKeys = Object.keys;
    var _keys = function (obj) {
        if (!_isObject(obj)) return [];
        if (nativeKeys) return nativeKeys(obj);
        var keys = [];
        for (var key in obj) if (_has(obj, key)) keys.push(key);
        return keys;
    };
    var createEscaper = function (map) {
        var escaper = function (match) {
            return map[match];
        };
        // Regexes for identifying a key that needs to be escaped
        var source = '(?:' + _keys(map).join('|') + ')';
        var testRegexp = RegExp(source);
        var replaceRegexp = RegExp(source, 'g');
        return function (string) {
            string = string == null ? '' : '' + string;
            return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
        };
    };
    var escapeMap = {
        '&': '&amp;',
        '<': '&lt;',
        '>': '&gt;',
        '"': '&quot;',
        "'": '&#x27;',
        '`': '&#x60;'
    };
    var escapes = {
        "'": "'",
        '\\': '\\',
        '\r': 'r',
        '\n': 'n',
        '\u2028': 'u2028',
        '\u2029': 'u2029'
    };
    var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
    var escapeChar = function (match) {
        return '\\' + escapes[match];
    };
    window._template = function (text) {
        var settings = {
            evaluate: /\[\[([\s\S]+?)\]\]/g,
            interpolate: /{=([\s\S]+?)}/g,
            escape: /{-([\s\S]+?)}/g
        };
        var matcher = RegExp([
            settings.escape.source,
            settings.interpolate.source,
            settings.evaluate.source
        ].join('|') + '|$', 'g');
        var index = 0;
        var source = "__p+='";
        text.replace(matcher, function (match, escape, interpolate, evaluate, offset) {
            source += text.slice(index, offset).replace(escaper, escapeChar);
            index = offset + match.length;
            if (escape) {
                source += "'+\n((__t=(" + escape + "))==null?'':_escape(__t))+\n'";
            } else if (interpolate) {
                source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
            } else if (evaluate) {
                source += "';\n" + evaluate + "\n__p+='";
            }
            return match;
        });
        source += "';\n";
        source = 'with(obj||{}){\n' + source + '}\n';
        source = "var __t,__p='',__j=Array.prototype.join," +
            "print=function(){__p+=__j.call(arguments,'');};\n" +
            source + 'return __p;\n';
        try {
            var render = new Function('obj', '_escape', source);
        } catch (e) {
            e.source = source;
            throw e;
        }
        var template = function (data) {
            var _escape = createEscaper(escapeMap);
            return render.call(this, data, _escape);
        };
        template.source = 'function(obj){\n' + source + '}';
        return template;
    };
    window._tpl = function (tplStr, data) {
        return  _template(tplStr)(data);
    };
})();
/**
 * jQuery md5 $.md5("I'm Persian.");
 */
(function (e) {
    var m = function (p, o) {
        return(p << o) | (p >>> (32 - o))
    };
    var a = function (s, p) {
        var u, o, r, t, q;
        r = (s & 2147483648);
        t = (p & 2147483648);
        u = (s & 1073741824);
        o = (p & 1073741824);
        q = (s & 1073741823) + (p & 1073741823);
        if (u & o) {
            return(q ^ 2147483648 ^ r ^ t)
        }
        if (u | o) {
            if (q & 1073741824) {
                return(q ^ 3221225472 ^ r ^ t)
            } else {
                return(q ^ 1073741824 ^ r ^ t)
            }
        } else {
            return(q ^ r ^ t)
        }
    };
    var n = function (o, q, p) {
        return(o & q) | ((~o) & p)
    };
    var l = function (o, q, p) {
        return(o & p) | (q & (~p))
    };
    var j = function (o, q, p) {
        return(o ^ q ^ p)
    };
    var i = function (o, q, p) {
        return(q ^ (o | (~p)))
    };
    var g = function (q, p, v, u, o, r, t) {
        q = a(q, a(a(n(p, v, u), o), t));
        return a(m(q, r), p)
    };
    var c = function (q, p, v, u, o, r, t) {
        q = a(q, a(a(l(p, v, u), o), t));
        return a(m(q, r), p)
    };
    var h = function (q, p, v, u, o, r, t) {
        q = a(q, a(a(j(p, v, u), o), t));
        return a(m(q, r), p)
    };
    var d = function (q, p, v, u, o, r, t) {
        q = a(q, a(a(i(p, v, u), o), t));
        return a(m(q, r), p)
    };
    var f = function (r) {
        var v;
        var q = r.length;
        var p = q + 8;
        var u = (p - (p % 64)) / 64;
        var t = (u + 1) * 16;
        var w = Array(t - 1);
        var o = 0;
        var s = 0;
        while (s < q) {
            v = (s - (s % 4)) / 4;
            o = (s % 4) * 8;
            w[v] = (w[v] | (r.charCodeAt(s) << o));
            s++
        }
        v = (s - (s % 4)) / 4;
        o = (s % 4) * 8;
        w[v] = w[v] | (128 << o);
        w[t - 2] = q << 3;
        w[t - 1] = q >>> 29;
        return w
    };
    var b = function (r) {
        var q = "", o = "", s, p;
        for (p = 0; p <= 3; p++) {
            s = (r >>> (p * 8)) & 255;
            o = "0" + s.toString(16);
            q = q + o.substr(o.length - 2, 2)
        }
        return q
    };
    var k = function (p) {
        p = p.replace(/\x0d\x0a/g, "\x0a");
        var o = "";
        for (var r = 0; r < p.length; r++) {
            var q = p.charCodeAt(r);
            if (q < 128) {
                o += String.fromCharCode(q)
            } else {
                if ((q > 127) && (q < 2048)) {
                    o += String.fromCharCode((q >> 6) | 192);
                    o += String.fromCharCode((q & 63) | 128)
                } else {
                    o += String.fromCharCode((q >> 12) | 224);
                    o += String.fromCharCode(((q >> 6) & 63) | 128);
                    o += String.fromCharCode((q & 63) | 128)
                }
            }
        }
        return o
    };
    e.extend({md5: function (o) {
        var v = Array();
        var G, H, p, u, F, Q, P, N, K;
        var D = 7, B = 12, z = 17, w = 22;
        var O = 5, L = 9, J = 14, I = 20;
        var t = 4, s = 11, r = 16, q = 23;
        var E = 6, C = 10, A = 15, y = 21;
        o = k(o);
        v = f(o);
        Q = 1732584193;
        P = 4023233417;
        N = 2562383102;
        K = 271733878;
        for (G = 0; G < v.length; G += 16) {
            H = Q;
            p = P;
            u = N;
            F = K;
            Q = g(Q, P, N, K, v[G + 0], D, 3614090360);
            K = g(K, Q, P, N, v[G + 1], B, 3905402710);
            N = g(N, K, Q, P, v[G + 2], z, 606105819);
            P = g(P, N, K, Q, v[G + 3], w, 3250441966);
            Q = g(Q, P, N, K, v[G + 4], D, 4118548399);
            K = g(K, Q, P, N, v[G + 5], B, 1200080426);
            N = g(N, K, Q, P, v[G + 6], z, 2821735955);
            P = g(P, N, K, Q, v[G + 7], w, 4249261313);
            Q = g(Q, P, N, K, v[G + 8], D, 1770035416);
            K = g(K, Q, P, N, v[G + 9], B, 2336552879);
            N = g(N, K, Q, P, v[G + 10], z, 4294925233);
            P = g(P, N, K, Q, v[G + 11], w, 2304563134);
            Q = g(Q, P, N, K, v[G + 12], D, 1804603682);
            K = g(K, Q, P, N, v[G + 13], B, 4254626195);
            N = g(N, K, Q, P, v[G + 14], z, 2792965006);
            P = g(P, N, K, Q, v[G + 15], w, 1236535329);
            Q = c(Q, P, N, K, v[G + 1], O, 4129170786);
            K = c(K, Q, P, N, v[G + 6], L, 3225465664);
            N = c(N, K, Q, P, v[G + 11], J, 643717713);
            P = c(P, N, K, Q, v[G + 0], I, 3921069994);
            Q = c(Q, P, N, K, v[G + 5], O, 3593408605);
            K = c(K, Q, P, N, v[G + 10], L, 38016083);
            N = c(N, K, Q, P, v[G + 15], J, 3634488961);
            P = c(P, N, K, Q, v[G + 4], I, 3889429448);
            Q = c(Q, P, N, K, v[G + 9], O, 568446438);
            K = c(K, Q, P, N, v[G + 14], L, 3275163606);
            N = c(N, K, Q, P, v[G + 3], J, 4107603335);
            P = c(P, N, K, Q, v[G + 8], I, 1163531501);
            Q = c(Q, P, N, K, v[G + 13], O, 2850285829);
            K = c(K, Q, P, N, v[G + 2], L, 4243563512);
            N = c(N, K, Q, P, v[G + 7], J, 1735328473);
            P = c(P, N, K, Q, v[G + 12], I, 2368359562);
            Q = h(Q, P, N, K, v[G + 5], t, 4294588738);
            K = h(K, Q, P, N, v[G + 8], s, 2272392833);
            N = h(N, K, Q, P, v[G + 11], r, 1839030562);
            P = h(P, N, K, Q, v[G + 14], q, 4259657740);
            Q = h(Q, P, N, K, v[G + 1], t, 2763975236);
            K = h(K, Q, P, N, v[G + 4], s, 1272893353);
            N = h(N, K, Q, P, v[G + 7], r, 4139469664);
            P = h(P, N, K, Q, v[G + 10], q, 3200236656);
            Q = h(Q, P, N, K, v[G + 13], t, 681279174);
            K = h(K, Q, P, N, v[G + 0], s, 3936430074);
            N = h(N, K, Q, P, v[G + 3], r, 3572445317);
            P = h(P, N, K, Q, v[G + 6], q, 76029189);
            Q = h(Q, P, N, K, v[G + 9], t, 3654602809);
            K = h(K, Q, P, N, v[G + 12], s, 3873151461);
            N = h(N, K, Q, P, v[G + 15], r, 530742520);
            P = h(P, N, K, Q, v[G + 2], q, 3299628645);
            Q = d(Q, P, N, K, v[G + 0], E, 4096336452);
            K = d(K, Q, P, N, v[G + 7], C, 1126891415);
            N = d(N, K, Q, P, v[G + 14], A, 2878612391);
            P = d(P, N, K, Q, v[G + 5], y, 4237533241);
            Q = d(Q, P, N, K, v[G + 12], E, 1700485571);
            K = d(K, Q, P, N, v[G + 3], C, 2399980690);
            N = d(N, K, Q, P, v[G + 10], A, 4293915773);
            P = d(P, N, K, Q, v[G + 1], y, 2240044497);
            Q = d(Q, P, N, K, v[G + 8], E, 1873313359);
            K = d(K, Q, P, N, v[G + 15], C, 4264355552);
            N = d(N, K, Q, P, v[G + 6], A, 2734768916);
            P = d(P, N, K, Q, v[G + 13], y, 1309151649);
            Q = d(Q, P, N, K, v[G + 4], E, 4149444226);
            K = d(K, Q, P, N, v[G + 11], C, 3174756917);
            N = d(N, K, Q, P, v[G + 2], A, 718787259);
            P = d(P, N, K, Q, v[G + 9], y, 3951481745);
            Q = a(Q, H);
            P = a(P, p);
            N = a(N, u);
            K = a(K, F)
        }
        var M = b(Q) + b(P) + b(N) + b(K);
        return M.toLowerCase()
    }})
})(jQuery);
/**
 * jQuery JSON plugin v2.5.1 $.toJSON $.evalJSON
 */
(function ($) {
    var escape = /["\\\x00-\x1f\x7f-\x9f]/g, meta = {"\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\"}, hasOwn = Object.prototype.hasOwnProperty;
    $.toJSON = typeof JSON === "object" && JSON.stringify ? JSON.stringify : function (o) {
        if (o === null) {
            return"null"
        }
        var pairs, k, name, val, type = $.type(o);
        if (type === "undefined") {
            return undefined
        }
        if (type === "number" || type === "boolean") {
            return String(o)
        }
        if (type === "string") {
            return $.quoteString(o)
        }
        if (typeof o.toJSON === "function") {
            return $.toJSON(o.toJSON())
        }
        if (type === "date") {
            var month = o.getUTCMonth() + 1, day = o.getUTCDate(), year = o.getUTCFullYear(), hours = o.getUTCHours(), minutes = o.getUTCMinutes(), seconds = o.getUTCSeconds(), milli = o.getUTCMilliseconds();
            if (month < 10) {
                month = "0" + month
            }
            if (day < 10) {
                day = "0" + day
            }
            if (hours < 10) {
                hours = "0" + hours
            }
            if (minutes < 10) {
                minutes = "0" + minutes
            }
            if (seconds < 10) {
                seconds = "0" + seconds
            }
            if (milli < 100) {
                milli = "0" + milli
            }
            if (milli < 10) {
                milli = "0" + milli
            }
            return'"' + year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "." + milli + 'Z"'
        }
        pairs = [];
        if ($.isArray(o)) {
            for (k = 0; k < o.length; k++) {
                pairs.push($.toJSON(o[k]) || "null")
            }
            return"[" + pairs.join(",") + "]"
        }
        if (typeof o === "object") {
            for (k in o) {
                if (hasOwn.call(o, k)) {
                    type = typeof k;
                    if (type === "number") {
                        name = '"' + k + '"'
                    } else {
                        if (type === "string") {
                            name = $.quoteString(k)
                        } else {
                            continue
                        }
                    }
                    type = typeof o[k];
                    if (type !== "function" && type !== "undefined") {
                        val = $.toJSON(o[k]);
                        pairs.push(name + ":" + val)
                    }
                }
            }
            return"{" + pairs.join(",") + "}"
        }
    };
    $.evalJSON = typeof JSON === "object" && JSON.parse ? JSON.parse : function (str) {
        return eval("(" + str + ")")
    };
    $.secureEvalJSON = typeof JSON === "object" && JSON.parse ? JSON.parse : function (str) {
        var filtered = str.replace(/\\["\\\/bfnrtu]/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, "");
        if (/^[\],:{}\s]*$/.test(filtered)) {
            return eval("(" + str + ")")
        }
        throw new SyntaxError("Error parsing JSON, source is not valid.")
    };
    $.quoteString = function (str) {
        if (str.match(escape)) {
            return'"' + str.replace(escape, function (a) {
                var c = meta[a];
                if (typeof c === "string") {
                    return c
                }
                c = a.charCodeAt();
                return"\\u00" + Math.floor(c / 16).toString(16) + (c % 16).toString(16)
            }) + '"'
        }
        return'"' + str + '"'
    }
}(jQuery));
        /* ! Lazy Load 1.9.7 - MIT license - Copyright 2010-2015 Mika Tuupola */
        !function (a, b, c, d) {
            var e = a(b);
            a.fn.lazyload = function (f) {
                function g() {
                    var b = 0;
                    i.each(function () {
                        var c = a(this);
                        if (!j.skip_invisible || c.is(":visible"))if (a.abovethetop(this, j) || a.leftofbegin(this, j)); else if (a.belowthefold(this, j) || a.rightoffold(this, j)) {
                            if (++b > j.failure_limit)return!1
                        } else c.trigger("appear"), b = 0
                    })
                }

                var h, i = this, j = {threshold: 0, failure_limit: 0, event: "scroll", effect: "show", container: b, data_attribute: "original", skip_invisible: !1, appear: null, load: null, placeholder: ""};
                return f && (d !== f.failurelimit && (f.failure_limit = f.failurelimit, delete f.failurelimit), d !== f.effectspeed && (f.effect_speed = f.effectspeed, delete f.effectspeed), a.extend(j, f)), h = j.container === d || j.container === b ? e : a(j.container), 0 === j.event.indexOf("scroll") && h.bind(j.event, function () {
                    return g()
                }), this.each(function () {
                    var b = this, c = a(b);
                    b.loaded = !1, (c.attr("src") === d || c.attr("src") === !1) && c.is("img") && c.attr("src", j.placeholder), c.one("appear", function () {
                        if (!this.loaded) {
                            if (j.appear) {
                                var d = i.length;
                                j.appear.call(b, d, j)
                            }
                            a("<img />").bind("load", function () {
                                var d = c.attr("data-" + j.data_attribute);
                                c.hide(), c.is("img") ? c.attr("src", d) : c.css("background-image", "url('" + d + "')"), c[j.effect](j.effect_speed), b.loaded = !0;
                                var e = a.grep(i, function (a) {
                                    return!a.loaded
                                });
                                if (i = a(e), j.load) {
                                    var f = i.length;
                                    j.load.call(b, f, j)
                                }
                            }).attr("src", c.attr("data-" + j.data_attribute))
                        }
                    }), 0 !== j.event.indexOf("scroll") && c.bind(j.event, function () {
                        b.loaded || c.trigger("appear")
                    })
                }), e.bind("resize", function () {
                    g()
                }), /(?:iphone|ipod|ipad).*os 5/gi.test(navigator.appVersion) && e.bind("pageshow", function (b) {
                    b.originalEvent && b.originalEvent.persisted && i.each(function () {
                        a(this).trigger("appear")
                    })
                }), a(c).ready(function () {
                    g()
                }), this
            }, a.belowthefold = function (c, f) {
                var g;
                return g = f.container === d || f.container === b ? (b.innerHeight ? b.innerHeight : e.height()) + e.scrollTop() : a(f.container).offset().top + a(f.container).height(), g <= a(c).offset().top - f.threshold
            }, a.rightoffold = function (c, f) {
                var g;
                return g = f.container === d || f.container === b ? e.width() + e.scrollLeft() : a(f.container).offset().left + a(f.container).width(), g <= a(c).offset().left - f.threshold
            }, a.abovethetop = function (c, f) {
                var g;
                return g = f.container === d || f.container === b ? e.scrollTop() : a(f.container).offset().top, g >= a(c).offset().top + f.threshold + a(c).height()
            }, a.leftofbegin = function (c, f) {
                var g;
                return g = f.container === d || f.container === b ? e.scrollLeft() : a(f.container).offset().left, g >= a(c).offset().left + f.threshold + a(c).width()
            }, a.inviewport = function (b, c) {
                return!(a.rightoffold(b, c) || a.leftofbegin(b, c) || a.belowthefold(b, c) || a.abovethetop(b, c))
            }, a.extend(a.expr[":"], {"below-the-fold": function (b) {
                return a.belowthefold(b, {threshold: 0})
            }, "above-the-top": function (b) {
                return!a.belowthefold(b, {threshold: 0})
            }, "right-of-screen": function (b) {
                return a.rightoffold(b, {threshold: 0})
            }, "left-of-screen": function (b) {
                return!a.rightoffold(b, {threshold: 0})
            }, "in-viewport": function (b) {
                return a.inviewport(b, {threshold: 0})
            }, "above-the-fold": function (b) {
                return!a.belowthefold(b, {threshold: 0})
            }, "right-of-fold": function (b) {
                return a.rightoffold(b, {threshold: 0})
            }, "left-of-fold": function (b) {
                return!a.rightoffold(b, {threshold: 0})
            }})
        }(jQuery, window, document);
// uuid
/**
 * UUID.core.js: The minimal subset of the RFC-compliant UUID generator UUID.js.
 * 
 * @fileOverview
 * @author LiosK
 * @version core-1.0
 * @license The MIT License: Copyright (c) 2012 LiosK.
 */

/** @constructor */
function UUID() {
}

/**
 * The simplest function to get an UUID string.
 * 
 * @returns {string} A version 4 UUID string.
 */
UUID.generate = function () {
    var rand = UUID._gri, hex = UUID._ha;
    return  hex(rand(32), 8)          // time_low
        + "-"
        + hex(rand(16), 4)          // time_mid
        + "-"
        + hex(0x4000 | rand(12), 4) // time_hi_and_version
        + "-"
        + hex(0x8000 | rand(14), 4) // clock_seq_hi_and_reserved clock_seq_low
        + "-"
        + hex(rand(48), 12);        // node
};
UUID.create = function () {
    return UUID.generate().replaceAll("-", "");
};
/**
 * Returns an unsigned x-bit random integer.
 * 
 * @param {int}
 *            x A positive integer ranging from 0 to 53, inclusive.
 * @returns {int} An unsigned x-bit random integer (0 <= f(x) < 2^x).
 */
UUID._gri = function (x) { // _getRandomInt
    if (x < 0) return NaN;
    if (x <= 30) return (0 | Math.random() * (1 << x));
    if (x <= 53) return (0 | Math.random() * (1 << 30))
        + (0 | Math.random() * (1 << x - 30)) * (1 << 30);
    return NaN;
};

/**
 * Converts an integer to a zero-filled hexadecimal string.
 * 
 * @param {int}
 *            num
 * @param {int}
 *            length
 * @returns {string}
 */
UUID._ha = function (num, length) {  // _hexAligner
    var str = num.toString(16), i = length - str.length, z = "0";
    for (; i > 0; i >>>= 1, z += z) {
        if (i & 1) {
            str = z + str;
        }
    }
    return str;
};

// 常用扩展
// String 扩展
(function () {
    String.prototype.trim = function () {
        var str = this;
        return str.replace(/(^[\s\u3000]*)|([\s\u3000]*$)/g, "");
    };
    String.prototype.format = function (args) {
        var result = this;
        if (arguments.length > 0) {

            if (arguments.length == 1 && typeof (args) == "object" && null != args) {
                for (var key in args) {
                    if (args[key] != undefined) {
                        if (null == args[key]) {
                            args[key] = ""
                        }
                        ;
                        var reg = new RegExp("({" + key + "})", "g");
                        result = result.replace(reg, args[key]);
                    }
                }
            } else {
                for (var i = 0; i < arguments.length; i++) {
                    if (arguments[i] != undefined) {
                        if (null == arguments[i]) {
                            arguments[i] = ""
                        }
                        ;
                        // var reg = new RegExp("({[" + i + "]})",
						// "g");//这个在索引大于9时会有问题，谢谢何以笙箫的指出
                        var reg = new RegExp("({)" + i + "(})", "g");
                        result = result.replace(reg, arguments[i]);
                    }
                }
            }
        }
        return result;
    };
    String.prototype.joinStr = function (args) {
        var str = "";
        var split = this;
        for (var i = 0; i < arguments.length; i++) {
            var item = arguments[i];
            if (null != item) {
                item = item.toString().trim();
                if ("" != item) {
                    str += item + split;
                }
            }
        }
        str = str.substring(0, str.length - split.length);
        return str;
    };
    String.prototype.t = function () {
        var str = this;
        str = str.replace(/-/g, "/");
        return str;
    };
    String.prototype.endWith = function (str) {
        if (str == null || str == "" || this.length == 0 || str.length > this.length)
            return false;
        if (this.substring(this.length - str.length) == str)
            return true;
        else
            return false;
        return true;
    };
    String.prototype.startWith = function (str) {
        if (str == null || str == "" || this.length == 0 || str.length > this.length)
            return false;
        if (this.substr(0, str.length) == str)
            return true;
        else
            return false;
        return true;
    };
    String.prototype.replaceAll = function (s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
    };
    String.prototype.isNumber = function () {
        if (parseFloat(this).toString() == "NaN") {
            return false;
        } else {
            return true;
        }
        ;
    };
    String.prototype.isEmpty = function () {
        if (null == this) {
            return true;
        }
        if ("" == this) {
            return true;
        }
        return false;
    };
    String.prototype.isBlank = function () {
        if (null == this) {
            return true;
        }
        if ("" == this.trim()) {
            return true;
        }
        return false;
    };
    String.prototype.init = function () {
        if (null == this) {
            return null;
        }
        if ("" == this.trim()) {
            return null;
        }
        return this;
    };
})();
// Array 扩展
(function () {
  /*
	 * Array.prototype.remove = function(dx) {
	 * if(isNaN(dx)||dx>this.length){return false;} this.splice(dx,1); }
	 */
    Array.prototype.remove=function(dx)
    {
        if(isNaN(dx)||dx>this.length){return false;}
        for(var i=0,n=0;i<this.length;i++)
        {
            if(this[i]!=this[dx])
            {
                this[n++]=this[i]
            }
        }
        this.length-=1
    }
})();

// Date 扩展
(function () {
    /**
	 * * 对Date的扩展，将 Date 转化为指定格式的String *
	 * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 个占位符 * 年(y)可以用 1-4
	 * 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) * eg: * (new Date()).pattern("yyyy-MM-dd
	 * hh:mm:ss.S")==> 2006-07-02 08:09:04.423 (new Date()).pattern("yyyy-MM-dd
	 * E HH:mm:ss") ==> 2009-03-10 二 20:09:04 (new Date()).pattern("yyyy-MM-dd
	 * EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04 (new Date()).pattern("yyyy-MM-dd
	 * EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04 (new Date()).pattern("yyyy-M-d
	 * h:m:s.S") ==> 2006-7-2 8:9:4.18
	 */
    Date.prototype.format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, // 月份
            "d+": this.getDate(), // 日
            "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, // 小时
            "H+": this.getHours(), // 小时
            "m+": this.getMinutes(), // 分
            "s+": this.getSeconds(), // 秒
            "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
            "S": this.getMilliseconds() // 毫秒
        };
        var week = {
            "0": "天",
            "1": "一",
            "2": "二",
            "3": "三",
            "4": "四",
            "5": "五",
            "6": "六"
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        if (/(E+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "星期" : "周") : "") + week[this.getDay() + ""]);
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }
        return fmt;
    };
    Date.prototype.toLocaleDate = function (mills) {
        var year = this.getFullYear();
        var month = this.getMonth() + 1;
        var day = this.getDate();
        var hour = this.getHours();
        var min = this.getMinutes();
        var seconds = this.getSeconds();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        if (hour < 10) {
            hour = "0" + hour;
        }
        if (min < 10) {
            min = "0" + min;
        }
        if (seconds < 10) {
            seconds = "0" + seconds;
        }

        return year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + seconds;
    };
    Date.prototype.toShortDate = function () {
        var year = this.getFullYear();
        var month = this.getMonth() + 1;
        var day = this.getDate();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        return year + '-' + month + '-' + day;
    };
})();

// jquery 扩展
(function ($) {
    $.isHtml5 = function () {
        if (!('localStorage' in window && window['localStorage'] !== null)) {
            return false;
        }
        return true;
    };
    $.isUndefined = function (obj) {
        if (typeof  obj == "undefined") {
            return true;
        }
        return false;
    };
    $.toFloat = function (obj) {
        if (null == $.Base.init(obj)) {
            return parseFloat(0);
        }
        if (obj.isNumber()) {
            return parseFloat(obj);
        }
        return parseFloat(0);
    };
    $.regNS = function (s) {
        var arr = s.split('.');
        var namespace = window;
        for (var i = 0, k = arr.length; i < k; i++) {
            if (typeof namespace[arr[i].trim()] == 'undefined') {
                namespace[arr[i].trim()] = {};
            }
            namespace = namespace[arr[i].trim()];
        }
        return namespace;
    };
    $.getNS = function (s) {
        var arr = s.split('.');
        var namespace = window;
        for (var i = 0, k = arr.length; i < k; i++) {
            if (typeof namespace[arr[i].trim()] == 'undefined') {
                return undefined;
            }
            namespace = namespace[arr[i].trim()];
        }
        return namespace;
    };
    $.delNS = function (s) {
        var arr = s.split('.');
        var namespace = window;

        for (var i = 0, k = arr.length; i < k; i++) {
            if (typeof namespace[arr[i]] == 'undefined') {
                return;
            } else if (k == i + 1) {
                delete  namespace[arr[i]];
                return;
            } else {
                namespace = namespace[arr[i]];
            }
        }
    };
    $.fn.isSee = function () {
        if ($(window).scrollTop() > ($(this).offset().top + jQuery(this).outerHeight())
            || (($(window).scrollTop() + $(window).height()) < $(this).offset().top)) {
            return false;
        }
        return true;
    };
    $.fn.ko = function (fromData, toData, data) {
        if ($.isUndefined(data)) {
            data = {reload: false};
        }
        if ($.isUndefined(data.reload)) {
            data.reload = false;
        }
        if (!data.reload) {
            toData = ko.mapping.fromJS(fromData);
            ko.applyBindings(toData, this[0]);
        } else {
            ko.mapping.fromJS(fromData, toData);
        }
        return toData;
    };
    $.once2s = function (id, callback, time) {// 2000ms内数据不可以相同
        var _time = 2000;
        if (!$.isUndefined(time)) {
            _time = time;
        }
        var md = $.md5(location.href + id);// 当前页
        var json = sessionStorage.getItem(md);
        if (null == json) {
            json = 0;
            $.setItemS(md + "_begin", new Date().getTime());
        }
        $.setItemS(md, 1);
        var time = new Date().getTime()
            - new Date(parseInt(sessionStorage.getItem(md + "_begin"))).getTime();
        if (json == 0 || time > _time) {
            if (time > _time) {
                if (json != 0 && null == sessionStorage.getItem(md + "_v")) {
                    return;
                }
                $.setItemS(md + "_begin", new Date().getTime());
                sessionStorage.removeItem(md + "_v");
            }
            callback();
            $.setItemS(md + "_v", 1);
        }
    };
})(jQuery);
//
// $.getQueryString('myParam');
(function ($) {
    $.extend({
        getQueryString: function (name) {
            function parseParams() {
                var params = {},
                    e,
                    a = /\+/g,  // Regex for replacing addition symbol with a
								// space
                    r = /([^&=]+)=?([^&]*)/g,
                    d = function (s) {
                        return decodeURIComponent(s.replace(a, " "));
                    },
                    q = window.location.search.substring(1);

                while (e = r.exec(q))
                    params[d(e[1])] = d(e[2]);

                return params;
            }

            if (!this.queryStringParams)
                this.queryStringParams = parseParams();

            return this.queryStringParams[name];
        }
    });
})(jQuery);


(function ($) {
    $.setItemS = function (key, value) {
        try {
            sessionStorage.setItem(key, value);
        } catch (ex) {
            console.dir(ex);
            // sessionStorage.clear();
            for (var i = sessionStorage.length - 1; i >= 0; i--) {
                var key = sessionStorage.key(i);
                console.dir(key);
                if (key.startWith("_zcache_")) {
                    sessionStorage.removeItem(key);
                }
            }
            sessionStorage.setItem(key, value);
        }
    };
    // string不用再序列化
    $.postz = function (url, param, callback) {
        var result = null;
        var md = "_zcache_" + $.md5(url + $.toJSON(param));
        var json = sessionStorage.getItem(md);
        if (null == json) {
            $.post(url, param, function (data) {
                if (typeof  data == "string") {
                    data = $.evalJSON(data);
                }
                $.setItemS(md, $.toJSON(data));
                data.reload = false;
                callback(data);
            });
        } else {
            result = $.evalJSON(json);
            result.reload = false;
            callback(result);
            var mdJson = $.md5(json);
            $.post(url, param, function (data) {
                var resultJsonStr = "";
                var resultData = null;
                if (typeof  data == "string") {
                    $.setItemS(md, data);
                    resultJsonStr = data;
                    resultData = $.evalJSON(data);
                } else {
                    var dataStr = $.toJSON(data);
                    $.setItemS(md, dataStr);
                    resultJsonStr = dataStr;
                    resultData = data;
                }
                if (mdJson != $.md5(resultJsonStr)) {
                    resultData.reload = true;
                    // callback(resultData);
                    // window.location.reload();
                }
            });
        }

    };
    $.postc = function (url, param, callback) {// 2000ms内数据不可以相同
        var _time = 1000;
        var md = $.md5(url + $.toJSON(param));
        var json = sessionStorage.getItem(md);
        if (null == json) {
            json = 0;
            $.setItemS(md + "_begin", new Date().getTime());
        }
        $.setItemS(md, 1);
        var time = new Date().getTime()
            - new Date(parseInt(sessionStorage.getItem(md + "_begin"))).getTime();
        if (json == 0 || time > _time) {
            if (time > _time) {
                if (json != 0 && null == sessionStorage.getItem(md + "_v")) {
                    return;
                }
                $.setItemS(md + "_begin", new Date().getTime());
                sessionStorage.removeItem(md + "_v");
            }
            $.post(url, param, function (data) {
                callback(data);
                $.setItemS(md + "_v", 1);
            });
        }
    };
}(jQuery));


// 必用库end

_Base = {
    init: function (obj) {
        if (typeof  obj == "undefined") {
            return null;
        }
        if (null == obj) {
            return null;
        }
        if (typeof  obj == "string") {
            if ("" == obj.trim()) {
                return null;
            }
        }
        return obj;
    },
    str: function () {
        var str = "";
        for (var i = 0; i < arguments.length; i++) {
            str += arguments[i];
        }
        return str;
    },
    clone: function (myObj) {
        return $.evalJSON($.toJSON(myObj));
    },
    enterDown: function (inputId, btnId) {
        $(inputId).keydown(function (event) {
            if (event.keyCode == 13) {
                $(btnId).click();
                $(inputId).blur();
            }
        });
    },
    open: function (url) {
        var a = $("<a href='{0}' target='_blank'>Apple</a>".format(url)).get(0);
        var e = document.createEvent('MouseEvents');
        e.initEvent('click', true, true);
        a.dispatchEvent(e);
    },
    go: function (url) {
        window.location.href = url;
    },
    qr: function (url) {
        return "{0}/weixinAPI/getQrCodePic?url={1}".format(eventURL, url);
    },
    gotoId: function (id, num) {
        if ($(id).length == 0) {
            return;
        }
        var _targetTop = $(id).offset().top;// 获取位置
        if (typeof num == "undefined") {
            num = 0;
        }
        _targetTop = _targetTop + num;
        jQuery("html,body").animate({scrollTop: _targetTop}, 100);// 跳转
    },
    gotoName: function (name, num) {
        if ($("[name={0}]".format(name)).length == 0) {
            return;
        }
        var _targetTop = $("[name={0}]".format(name)).offset().top;// 获取位置
        if (typeof num == "undefined") {
            num = 0;
        }
        _targetTop = _targetTop + num;
        jQuery("html,body").animate({scrollTop: _targetTop}, 100);// 跳转
    },
    onerror: function (src) {
        var img = event.srcElement;
        img.src = src;
        img.onerror = null; // 控制不要一直跳动
    },
    removeHTMLTag: function (str) {
        if (null == _Base.init(str)) {
            return "";
        }
        str = str.replace(/<\/?[^>]*>/g, ''); // 去除HTML tag
        str = str.replace(/[ | ]*\n/g, '\n'); // 去除行尾空白
        // str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
        str = str.replace(/ /ig, '');// 去掉
        return str;
    },
    evalJSON: function (data) {
        if (typeof  data == "string") {
            data = $.evalJSON(data);
        }
        return data;
    },
    result:function(data,success,fail){
        if("success"==data.status){
            if(typeof success=="undefined"){
                layer.closeAll();
                layer.info(data.msg);
            }else{
                success(data);
            }
        }
        if("fail"==data.status){
            if(typeof fail=="undefined"){
                layer.closeAll();
                layer.error(data.msg);
            }else{
                fail(data);
            }
        }
    }
};
var _URL={
    toShortURL:function(url,cal){
        $.ajax({
            'url' : eventURL+"util/shortURL.do",
            'type' : 'POST',
            'data' : {url:url},
            'async' : true,
            'dataType' : 'json',
            'success' : function(data) {
                cal(data);
            }
        });
    }
};
var _IDNumber = {
    getData: function (idCard) {
        var IDBean = {};
        var birthday = "";
        if (idCard != null && idCard != "") {
            if (idCard.length == 15) {
                birthday = "19" + idCard.substr(6, 6);
            } else if (idCard.length == 18) {
                birthday = idCard.substr(6, 8);
            }

            birthday = birthday.replace(/(.{4})(.{2})/, "$1-$2-");
        }
        IDBean.birthDay = birthday;
        return IDBean;
    }
};
var _Date = {

    toDeadLine: function (deadline) {
        var str = "";
        var startDate = new Date();
        var month = this.getDateMonthSub(startDate.getTime(), deadline);
        if (month > 0) {
            str += _NoToChinese(month) + "个月";
            startDate = this.DateAdd("m", month, startDate);
        }
        var day = this.getDateDaySub(startDate.getTime(), deadline);
        if (day > 0) {
            var dayStr = _NoToChinese(day);
            str += dayStr + "天";
            startDate = this.DateAdd("d", day, startDate);
        }
        var hour = this.getDateHourSub(startDate.getTime(), deadline);
        if (hour > 0 && day == 0) {
            str += _NoToChinese(hour) + "个小时";
        }
        return str;
    },
    getDateDaySub: function (startDate, endDate) {
        if (startDate == null || startDate == undefined || startDate == ""
            || endDate == null || endDate == undefined || endDate == "")
            return 0;
        var endDate = new Date(endDate);
        var startDate = new Date(startDate);
        var day = (endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24);
        return parseInt(day);
    },
    getDateHourSub: function (startDate, endDate) {
        if (startDate == null || startDate == undefined || startDate == ""
            || endDate == null || endDate == undefined || endDate == "")
            return 0;
        var endDate = new Date(endDate);
        var startDate = new Date(startDate);
        var hour = (endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60);
        return parseInt(hour);
    },
    getDateHourSub: function (startDate, endDate) {
        if (startDate == null || startDate == undefined || startDate == ""
            || endDate == null || endDate == undefined || endDate == "")
            return 0;
        var endDate = new Date(endDate);
        var startDate = new Date(startDate);
        var hour = (endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60);
        return parseInt(hour);
    },
    /**
	 * *判断是否为当年当月的最后一天
	 */
    isLastDay: function (yearV, monthV, dayV) {
        var new_year = yearV; // 取当前的年份
        var new_month = monthV + 1;// 取下一个月的第一天，方便计算（最后一天不固定）
        if (new_month > 12) // 如果当前大于12月，则年份转到下一年
        {
            new_month -= 12; // 月份减
            new_year++; // 年份增
        }
        var new_date = new Date(new_year, new_month, 1); // 取当年当月中的第一天
        var lastDay = (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate();// 获取当月最后一天日期
        if (lastDay == dayV) {
            return true;
        } else {
            return false;
        }
    },
    /**
	 * *计算距离月底还有几天
	 */
    getLastDayAway: function (yearV, monthV, dayV) {
        var new_year = yearV; // 取当前的年份
        var new_month = monthV + 1;// 取下一个月的第一天，方便计算（最后一天不固定）
        if (new_month > 12) // 如果当前大于12月，则年份转到下一年
        {
            new_month -= 12; // 月份减
            new_year++; // 年份增
        }
        var new_date = new Date(new_year, new_month, 1); // 取当年当月中的第一天
        var lastDay = (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate();// 获取当月最后一天日期
        var away_day = lastDay - dayV;
        return away_day;
    },
    /**
	 * @param startDate
	 *            开始日期
	 * @param endDate
	 *            结束日期
	 * @return 计算相差月份，必须满足正好一个月才进一
	 */
    getDateMonthSub: function (startDate, endDate) {
        if (startDate == null || startDate == undefined || startDate == ""
            || endDate == null || endDate == undefined || endDate == "")
            return 0;
        var endDate = new Date(endDate);
        var startDate = new Date(startDate);
        var renNumber = 0;
        var yearToMonth = (endDate.getFullYear() - startDate.getFullYear()) * 12;
// 计算年份相差月份
        renNumber += yearToMonth;
        var startYear = startDate.getFullYear();// 开始日期-年份
        var endYear = endDate.getFullYear();// 结束日期-年份
        var startMon = startDate.getMonth();// 开始日期-月份
        var endMon = endDate.getMonth();// 结束日期-月份
        var startDay = startDate.getDate();// 开始日期-日
        var endDay = endDate.getDate();// 开始日期-日
        var monthToMonth = endDate.getMonth() - startDate.getMonth();
// 计算月份相差
        renNumber += monthToMonth;
// 如果开始日期是最后一天并且结束日期不是最后一天，那么返回值-1
        if (this.isLastDay(startYear, startMon, startDay)
            && !this.isLastDay(endYear, endMon, endDay)) {
            renNumber -= 1;
            return renNumber;
        } else {
// 如果开始日期和结束日期都不是最后一天
            if (!this.isLastDay(startYear, startMon, startDay)
                && !this.isLastDay(endYear, endMon, endDay)) {
// 如果都不是最后一天，就需要计算开始日期和结束日期的天数距离结束还有几天,分别为start_last,end_last
                var start_last = this.getLastDayAway(startYear, startMon, startDay);
                var end_last = this.getLastDayAway(endYear, endMon, endDay);

// 如果结束日期距离月底的天数比开始日期距离月底的天数大，则返回值-1
                if (end_last > start_last) {
                    renNumber -= 1;
                    return renNumber;
                } else {
                    return renNumber;
                }
            } else {
// 如果开始日期和结束日期的天都是当月的最后一天，那么相差月份就是实际月份相减的值
// 其他情况都直接返回renNumber
                return renNumber;
            }
        }
    },

// 创建实例
    DateAdd: function (interval, number, date) {
        /*
		 * 功能:实现VBScript的DateAdd功能. 参数:interval,字符串表达式，表示要添加的时间间隔.
		 * 参数:number,数值表达式，表示要添加的时间间隔的个数. 参数:date,时间对象. 返回:新的时间对象. var now = new
		 * Date(); var newDate = DateAdd( "d ",5,now); ---------------
		 * DateAdd(interval,number,date) -----------------
		 */
        switch (interval) {
            case   "y"   :
            {
                date.setFullYear(date.getFullYear() + number);
                return   date;
                break;
            }
            case   "q"   :
            {
                date.setMonth(date.getMonth() + number * 3);
                return   date;
                break;
            }
            case   "m"   :
            {
                date.setMonth(date.getMonth() + number);
                return   date;
                break;
            }
            case   "w"   :
            {
                date.setDate(date.getDate() + number * 7);
                return   date;
                break;
            }
            case   "d"   :
            {
                date.setDate(date.getDate() + number);
                return   date;
                break;
            }
            case   "h"   :
            {
                date.setHours(date.getHours() + number);
                return   date;
                break;
            }
            case   "m"   :
            {
                date.setMinutes(date.getMinutes() + number);
                return   date;
                break;
            }
            case   "s"   :
            {
                date.setSeconds(date.getSeconds() + number);
                return   date;
                break;
            }
            default   :
            {
                date.setDate(d.getDate() + number);
                return   date;
                break;
            }
        }
    }


};
var _NoToChinese = function (num) {
    return num;
    if (!/^\d*(\.\d*)?$/.test(num)) {
        alert("Number is wrong!");
        return "Number is wrong!";
    }
    var AA = new Array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九");
    var BB = new Array("", "十", "百", "千", "万", "亿", "点", "");
    var a = ("" + num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
    for (var i = a[0].length - 1; i >= 0; i--) {
        switch (k) {
            case 0:
                re = BB[7] + re;
                break;
            case 4:
                if (!new RegExp("0{4}\\d{" + (a[0].length - i - 1) + "}$").test(a[0]))
                    re = BB[4] + re;
                break;
            case 8:
                re = BB[5] + re;
                BB[7] = BB[5];
                k = 0;
                break;
        }
        if (k % 4 == 2 && a[0].charAt(i + 2) != 0 && a[0].charAt(i + 1) == 0) re = AA[0] + re;
        if (a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k % 4] + re;
        k++;
    }

    if (a.length > 1) // 加上小数部分(如果有小数部分)
    {
        re += BB[6];
        for (var i = 0; i < a[1].length; i++) re += AA[a[1].charAt(i)];
    }
    if (re.length > 1) {
        if ("一" == re.charAt(0)) {
            re = re.substring(1);
        }
    }
    return re;
};


var _nextPage = function (callback, offset, id) {
    if (typeof  offset == "undefined") {
        offset = 0;
    }
    if ($.isUndefined(id)) {
        // id=window;
    } else {
        console.dir($(id).isSee());
        if (!$(id).isSee()) {
            return;
        }
    }
    $(window).scroll(function () {
        // 当内容滚动到底部时加载新的内容
        if ($(this).scrollTop() + $(window).height() + offset >= $(document).height() && $(this).scrollTop() > offset) {
            // 当前要加载的页码
            callback.call(this);
        }
    });
};
var _delNextPage = function () {
    $(window).unbind('scroll');
};

$(function () {
    // 防止session失效 10分钟请求一次
   /* setInterval(function () {
       $.post(baseURL + "common/session.do", null, function (data) {
            console.dir(data.msg);
        });
    }, 1000 * 60 * 10);*/
    // 判断是否支持html5特性
    if (!$.isHtml5()) {
        alert("您的浏览器版本过低，不支持时髦的Html5的特性，请更换或升级浏览器");
        return;
    }
    $("img[data-src]").lazyload({threshold: 200, data_attribute: "src" });// 图片懒加载
});


